﻿namespace Blaze.Framework
{
    using System;
    using System.Collections.Generic;
    using Logging;

    /// <summary>
    /// 日志管理器。
    /// </summary>
    public static class LogManager
    {
        /// <summary>
        /// 获取或设置一个值，表示调试日志的总开关是否开启。
        /// </summary>
        public static bool IsDebugEnabled
        {
            get { return mIsDebugEnabled; }
            set { mIsDebugEnabled = value; }
        }

        /// <summary>
        /// 获取或创建一个日志记录器，并以其全名作为模块名。
        /// </summary>
        /// <param name="type">类型</param>
        /// <returns>日志记录器</returns>
        public static Log GetLogger(Type type)
        {
            if (type == null)
                throw new ArgumentNullException("type");
            return GetLogger(type.FullName);
        }

        /// <summary>
        /// 获取或创建指定模块名称的日志记录器。
        /// </summary>
        /// <param name="moduleName">模块名称</param>
        /// <returns>日志记录器</returns>
        public static Log GetLogger(string moduleName)
        {
            if (moduleName == null)
                moduleName = string.Empty;

            Log ret;
            if (!mLoggers.TryGetValue(moduleName, out ret))
            {
                ret = new Log(moduleName);
                mLoggers.Add(moduleName, ret);
            }

            return ret;
        }

        private static readonly Dictionary<string, Log> mLoggers = new Dictionary<string, Log>(128);
        private static bool mIsDebugEnabled = true;
    }
}